CSharpTest.Net
OrdinalList Constructor(Byte[])
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > OrdinalList Class > OrdinalList Constructor : OrdinalList Constructor(Byte[])

fromBits

Glossary Item Box

Constructs an OrdinalList from a set of bits represeting the ordinals

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal fromBits() As Byte _
)
C# 
public OrdinalList( 
   byte[] fromBits
)

Parameters

fromBits

Example

Library/Library.Test/TestOrdinalList.cs

C#Copy Code
OrdinalList list = new OrdinalList();
Assert.IsFalse(list.IsReadOnly);
list.Ceiling = 0;

for (int i = 512; i >= 0; i--)
    list.Add(i);

int offset = 0;
foreach (int item in list)
    Assert.AreEqual(offset++, item);

Assert.AreEqual(513, offset);
Assert.AreEqual(513, list.Count);
Assert.AreEqual(519, list.Ceiling);

list.Clear();
list.AddRange(new int[] { 5, 10, 20 });
list.AddRange(new int[] { });

Assert.AreEqual(3, list.Count);
Assert.AreEqual(23, list.Ceiling);

Assert.IsTrue(list.Contains(20));
Assert.IsTrue(list.Remove(20));

Assert.IsFalse(list.Contains(20));
Assert.IsFalse(list.Remove(20));

Assert.AreEqual(2, list.Count);

int[] items = new int[2];
list.CopyTo(items, 0);
Assert.AreEqual(5, items[0]);
Assert.AreEqual(10, items[1]);

items = list.ToArray();
Assert.AreEqual(5, items[0]);
Assert.AreEqual(10, items[1]);

byte[] bits = list.ToByteArray();
Assert.AreEqual(3, bits.Length);
Assert.AreEqual(2, new OrdinalList(bits).Count);

List<int> tmp = new List<int>();
foreach (int i in list)
    tmp.Add(i);
Assert.AreEqual(2, tmp.Count);
Assert.AreEqual(5, tmp[0]);
Assert.AreEqual(10, tmp[1]);
VB.NETCopy Code
Dim list As New OrdinalList()
Assert.IsFalse(list.IsReadOnly)
list.Ceiling = 0

Dim i As Integer = 512
While i >= 0
    list.Add(i)
    System.Math.Max(System.Threading.Interlocked.Decrement(i),i + 1)
End While

Dim offset As Integer = 0
For Each item As Integer In list
    Assert.AreEqual(System.Math.Max(System.Threading.Interlocked.Increment(offset),offset - 1), item)
Next

Assert.AreEqual(513, offset)
Assert.AreEqual(513, list.Count)
Assert.AreEqual(519, list.Ceiling)

list.Clear()
list.AddRange(New Integer() {5, 10, 20})
list.AddRange(New Integer() {})

Assert.AreEqual(3, list.Count)
Assert.AreEqual(23, list.Ceiling)

Assert.IsTrue(list.Contains(20))
Assert.IsTrue(list.Remove(20))

Assert.IsFalse(list.Contains(20))
Assert.IsFalse(list.Remove(20))

Assert.AreEqual(2, list.Count)

Dim items As Integer() = New Integer(2) {}
list.CopyTo(items, 0)
Assert.AreEqual(5, items(0))
Assert.AreEqual(10, items(1))

items = list.ToArray()
Assert.AreEqual(5, items(0))
Assert.AreEqual(10, items(1))

Dim bits As Byte() = list.ToByteArray()
Assert.AreEqual(3, bits.Length)
Assert.AreEqual(2, New OrdinalList(bits).Count)

Dim tmp As New List(Of Integer)()
For Each i As Integer In list
    tmp.Add(i)
Next
Assert.AreEqual(2, tmp.Count)
Assert.AreEqual(5, tmp(0))
Assert.AreEqual(10, tmp(1))

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys